
import json
import os
import requests


def webserviceEncryption(path,id,url,headers):
    print(path)


    # os.path.expanduser(path)
    headxml=path+'ListData'+str(id)+'.txt'
    bodyxml=path+'XMLBODY.txt'

    print(headxml)

    with open(headxml, "r", encoding='utf-8') as f:
        HeadXML = f.read()
        f.close()
    print(HeadXML)
    with open(bodyxml, "r", encoding='utf-8') as f:
        BODYXML = f.read()
        f.close()
    print(BODYXML)



    payload = {"reqHead": HeadXML,
        "reqBody": BODYXML}

    payload = json.dumps(payload)#
    payload = payload.encode("utf-8")

    response = requests.request("POST", url, headers=headers, data=payload)

    print(response.text)

    responseDict=eval(response.text)
    print(responseDict['data'])
    resHead=responseDict['data']['resHead']
    print(resHead)
    resBody = responseDict['data']['resBody']
    print(resBody)
    res={"resHead":resHead,"resBody":resBody}
    return  res


if __name__ == '__main__':
    path = "../case/files/"
    url = "http://192.168.16.12:6789/api/test/gzzcdZzEncrypt"  # 加密地址
    headers = {
        'Content-Type': 'application/json'
    }
    id=22
    result=webserviceEncryption(path,id,url,headers)
    print(111111222)
    print(result)
